<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>通过transform-origin实现特殊hover效果</title>
  <style>
    body {
      padding: 50px;
    }

    div {
      position: absolute;
      width: 200px;
      height: 60px;
      line-height: 60px;
      font-size: 32px;
      cursor: pointer;
      color: #333;
      text-align: center;
      transition: color .5s;
      margin: 20px;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }

    div::before {
      content: "";
      position: absolute;
      left: 0%;
      bottom: 0;
      width: 200px;
      transform: scaleX(0);
      height: 2px;
      background: deeppink;
      z-index: -1;
      /* hover离开的时候，下划线以100%为原点往右收缩 */
      transition: transform .5s;
      transform-origin: 100% 0;
    }

    div:hover::before {
      /* 开始hover的时候，下划线从左到后开始进入 */
      transform: scaleX(1);
      transform-origin: 0 0;
    }
  </style>
</head>

<body>
  <div>Hover Me</div>
</body>

</html>